package ccnt.pvc.scudwaremobile.activity;

import ccnt.pvc.scudwaremobile.R;
import ccnt.pvc.scudwaremobile.dao.ServiceModel;
import ccnt.pvc.scudwaremobile.storage.ServiceDbManager;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class ServiceDetailActivity extends Activity {

	ServiceDbManager serviceDbManager;
	ServiceModel serviceModel;
	String className;
	boolean isReg;
	
	TextView textServiceDetail;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_servicedetail);
		
		Bundle bundle = getIntent().getExtras();
		className = bundle.getString("className");
		isReg = bundle.getBoolean("isReg");
		
		initService();
		initView();
	}
	
	private void initService() {
		serviceDbManager = new ServiceDbManager(ServiceDetailActivity.this);
	}
	
	private void initView() {
		textServiceDetail = (TextView)findViewById(R.id.textServiceDetail);
		
		if(isReg) {
			serviceModel = serviceDbManager.getRegServiceByClassName(className);
		} else {
			serviceModel = serviceDbManager.getServiceByClassName(className);
		}
		
		StringBuilder builder = new StringBuilder();
		builder.append("类名：" + serviceModel.getClassName() + "\n");
		builder.append("包名：" + serviceModel.getPackageName() + "\n");
		builder.append("所属设备：" + serviceModel.getDeviceName() + "\n");
		builder.append("服务类型：" + (serviceModel.getCategory() == 1 ? "数据服务" : "应用服务") + "\n");
		builder.append("传感器：" + serviceModel.getSensorName() + "\n");
		builder.append("数据分类：" + serviceModel.getDataType() + "\n");
		builder.append("度量：" + serviceModel.getMeasure() + "\n");
		builder.append("服务类型：" + (serviceModel.getLevel() == 0 ? "raw" : "inferred") + "\n");
		builder.append("参数：" + serviceModel.getParams() + "\n");
		builder.append("描述：" + serviceModel.getDescription() + "\n");
		textServiceDetail.setText(builder.toString());
	}
}

